

package com.hazelcast.spi.impl.operationservice.impl.operations;

import com.hazelcast.client.impl.operations.OperationFactoryWrapper;
import com.hazelcast.spi.impl.operationservice.OperationFactory;

public final class PartitionAwareFactoryAccessor {

    private PartitionAwareFactoryAccessor() {
    }

    /**
     * @param operationFactory operationFactory
     * @return extracted {@code PartitionAwareOperationFactory} from supplied operation factory or null
     */
    public static PartitionAwareOperationFactory extractPartitionAware(OperationFactory operationFactory) {
        if (operationFactory instanceof PartitionAwareOperationFactory factory) {
            return factory;
        }

        if (operationFactory instanceof OperationFactoryWrapper wrapper) {
            OperationFactory unwrapped = wrapper.getOperationFactory();
            if (unwrapped instanceof PartitionAwareOperationFactory factory) {
                return factory;
            }
        }

        return null;
    }

}
